"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fallback = void 0;
const path_1 = __importDefault(require("path"));
const core_1 = require("../core");
/**
 * Fallback complete hook
 */
const fallback = async (ctx) => {
    console.log(`Created a new project in \`${ctx.project}\` by the \`${ctx.template}\` template.\n`);
    ctx.files.map(i => i.path).sort((a, b) => a > b ? +1 : -1).forEach(i => console.log('- ' + i));
    console.log('\nHappy hacking :)');
};
exports.fallback = fallback;
/**
 * Apply template complete hook.
 */
exports.default = async (ctx) => {
    const { dest } = ctx;
    const indexPath = path_1.default.join(dest, 'index.js');
    if (core_1.file.exists(indexPath)) { // 删除模板的配置文件
        core_1.file.remove(indexPath);
    }
    if (ctx.config.complete == null) {
        return await exports.fallback(ctx);
    }
    if (typeof ctx.config.complete === 'string') {
        return console.log(ctx.config.complete);
    }
    const result = await ctx.config.complete(ctx);
    if (result == null)
        return;
    console.log(result);
};
